package MD5Hash;

import java.util.*;

public class HashIt {
	
	public static void main(String[] args) {
		String input;
		boolean quit = false;
		Scanner in = new Scanner(System.in);
		System.out.print("Welcome to the MD5 Hash Program\n");
		while(!quit) {
			System.out.print("What would you like to do?\n" +
					"\t1) Hash\n\t2) Unhash\n\t3) Exit\nChoice: ");
			input = in.nextLine();
			if(input.contains("1"))
				hash();
			else if(input.contains("2"))
				unhash();
			else if(input.contains("3"))
				quit = true;
			else
				System.out.println("I'm sorry that is not recognized as valid input.\nPlease try again\n");
		}
		System.out.println("Goodbye!\n");
	}
	
	public static void hash() {
		Scanner in = new Scanner(System.in);
		String inputString;
		System.out.print("\nPlease enter the string you would like to hash.\nInput String: ");
		inputString = in.nextLine();
		String hexString = stringToHex(inputString);
		int length = hexString.length();
		
	}
	
	public static void unhash() {
		
	}
	
	public static String stringToHex(String input) {
		String output = "";
		char[] inputArray = input.toCharArray();
		int size = inputArray.length;
		for(int i = 0; i < size; i++) {
			char firstDigit;
			char secondDigit;
			int ascii = (int)inputArray[i];
			firstDigit = (char)(48 + (ascii / 16));
			secondDigit =(char)(48 + (ascii % 16));
			if((int)secondDigit > 57)
				secondDigit = (char)((int)secondDigit + 39);
			if(firstDigit == '0')
				output = output + secondDigit;
			else
				output = output + firstDigit + secondDigit;
		}
		return output;
	}
}
